Component({
  properties: {
    title: {
      type: String,
      value: ''
    },
    padding: {
      type: String,
      value: '0px'
    },
    ricon: {
      type: String,
      value: ''
    },
    uiListData: {
      type: Array,
      value: []
    },
    defaultValue: {
      type: String,
      value: '',
      observer(newVal, oldVal, changedPath) {
        this.setData({
          uiValues: newVal.split(',').filter(i => i)
        })
      }
    },
  },
  data: {
    uiShow: false,
    // uiListData: [],
    uiCheckedItems: [],
    uiCheckedItemCount: 0,
    uiCheckedItemNames: '',
    uiValues: []
  },
  methods: {
    handleHide(e) {
      this.setData({ uiShow: false })
      this.triggerEvent('hideEvent', e)
    },
    handleClose(e) {
      this.triggerEvent('closeEvent', e)
    },
    handleShow(e, params) {
      const { uiListData, defaultValue } = this.data
      const uiValues = defaultValue.split(',').filter(i => i !== '').map(i => Number(i))

      uiListData.map(i => i.checked = Boolean(uiValues.indexOf(i.id) >= 0))

      this.setData({
        uiShow: true,
        uiValues,
        uiListData
      })
      this.triggerEvent('showEvent', e)
    },
    handleCheck(e) {
      const { item } = e.currentTarget.dataset
      const { uiListData } = this.data
      const { id } = item

      let one = uiListData.find(i => i.id === id)
      // uiListData.map(i => i.checked = false)
      one.checked = !one.checked

      const allItem = uiListData.find(i => i.name === '所有门店')
      const norItem = uiListData.filter(i => i.name !== '所有门店')


      console.log({
        uiListData,
        uiCheckedItems: norItem.filter(i => i.checked)
      })
      this.setData({
        uiListData,
        uiCheckedItems: norItem.filter(i => i.checked)
      })
    },
    handleConfirm(e) {
      this.handleHide()
      const uiValues = this.data.uiListData.filter(i => i.checked).map(i => i.id).join(',')
      this.triggerEvent('confirmEvent', uiValues)
    }
  }
})
